import http from '@/http'

// 搜索
export const CloudSearch = (config: { limit?: number, offset?: number, keywords: string }): Promise<{
  code:number,
  result: {
    searchQcReminder: null,
    songCount: number,
    songs: {
      al: {
        id: number,
        name: string,
        pic: number,
        picUrl: string,
        pic_str: string,
        tns: []
      },
      ar: {
        alias: [],
        id: number,
        name: string,
        tns: []
      }[],
      cd: string,
      id: number,
      mark: number,
      name: string,
      publishTime: number,
    }[]
  }
}> => {
  const params = {
    limit: 30,
    offset: 1,
    ...config,
  }
  return http.get('/cloudsearch', { params })
}

// 获取搜索关键词
export const Default = () => {
  return http.get('/search/default')
}

// 获取热门搜索关键字(简略)
export const Hot = (): Promise<{
  code: number,
  result: { hots: { first: string, second: number, third: null, iconType: number }[] }
}> => {
  return http.get('/search/hot')
}

//  获取热门热搜列表(详细)
export const HotDetail = () => {
  return http.get('/search/hot/detail')
}

// 获取搜索建议
export const Suggest = (config: { type?: string, keywords: string }): Promise<{
  result: { allMatch: { alg: string, feature: string, keyword: string, lastKeyword: string, type: number }[] },
  code: number
}> => {
  const params = {
    type: 'mobile',
    ...config,
  }
  return http.get('/search/suggest', { params })
}

// 获取歌词
export const getLyrics = (id: number):Promise<{lrc: { lyric:string }}> => {
  return http.get('/lyric', { params: { id } })
}

// 获取音乐 url - 新版
export const getMusicUrl = async (id: number) => {
  return (await http.get('/song/url/v1', { params: { id, level: 'jymaster' } })).data[0].url
}

// 推荐新音乐
export const getNewMusic = (limit:number = 10):Promise<{
  code: number,
  result: {
    id: number,
    name: string,
  }[]
}> => {
  return http.get('/personalized/newsong', { params: { limit } })
}
